package com.hui.java.Synchronized;

/**
 * TODO:
 *
 * @author chenth
 * @create 2019-09-07 20:07
 **/
public class SynchronizedClass2 implements Runnable {
    static int i = 0;

    @Override
    public void run() {
        synchronized (this){
            for (int j = 0; j < 100000; j++) {
                i++;
            }
        }

    }

    public static void main(String[] args) {
        SynchronizedClass2 synchronizedClass2 = new SynchronizedClass2();
        Thread t1 = new Thread(synchronizedClass2);
        Thread t2 = new Thread(synchronizedClass2);
        t1.start();
        t2.start();
        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(i);
    }
}
